﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Data.OracleClient;
using ReflectionStudio.Core.Events;
namespace WPFExcelReport
{
    class MVTVKEKReport : BaseReport
    {
        #region ----------------PROPERTIES----------------------------------
        public OracleConnection OracleDB;
        public OracleCommand orlReadCommand = new OracleCommand();
        public IntexReptServBLClient proxy;
        private Dictionary<string, object> dicParamater;
        public DataSet dsResult;
        public DataSet setUI = new DataSet();
        string ABPAUFFKRS;
        string ABPAUFFLFD;
        string ABPAUFFPOS;
        string DocType;
        string CellName = "";
        string CellValue = "";
        string strCompany;
        string strExcelFile;
        #endregion
        public MVTVKEKReport()
            : base()
        {
        }
        public MVTVKEKReport(Dictionary<string, object> dicParamater)
            : base(dicParamater)
        {
            DocType = dicParamater["DocType"].ToString().Trim();
            strCompany = dicParamater["Company"].ToString().Trim();
            strExcelFile = dicParamater["ExcelFile"].ToString().Trim();
            #region Excel  columns
            columns.Add("DD");
            columns.Add("KUNDNR");
            columns.Add("PI");
            columns.Add("VKPAUFPOS");
            columns.Add("VKPKDKOMM");
            columns.Add("VKPART");
            columns.Add("VKPFARBE");
            columns.Add("VKQTY");
            columns.Add("VKPMEEH");
            columns.Add("VKPLIEFTERM");
            columns.Add("LSLIEFNA");
            columns.Add("EKPLSART");
            columns.Add("EKPLSFB");
            columns.Add("EKQTY");
            columns.Add("EKPMEEH");
            columns.Add("EKPWUTERM");
            columns.Add("EKPLTERM");
            columns.Add("EKPNEUD");
            columns.Add("VKKANSPZUS");
            columns.Add("VKKNEUBEN");
            columns.Add("VKKSACHBE");
            #endregion           						
            
        }
        #region------------------------------Function------------------------

        public void FillInExcelData(ArrayList columns, DataSet setSoruce, int xStart = 2, int yStart = 1)
        {
            try
            {
                int x = xStart, y = yStart;
                
                string SUP = "";
                Int32 I = 0;
                DataTable dtSoruce = setSoruce.Tables["VKEK"];
                foreach (DataRow dataRow in dtSoruce.Rows)
                {
                    y = yStart;
                    foreach (string column in columns)
                    {
                        exAgent.SetCellValue(x, y, dataRow[column].ToString());                        
                        y++;
                    }
                    SUP = dataRow["LSLIEFNA"].ToString().Trim();
                    //if (SUP == "" )
                    //{
                        
                        //exAgent.WorkSheet.Rows[x].Font.Color = 50000;
                    //}
                    I = System.Convert.ToInt32(dataRow["DD"].ToString().Trim());
                    if (I > 15 && SUP != "")
                    {
                        exAgent.WorkSheet.Rows[x].Font.Color = 50000;
                    }
                    if (I <= 15 && I > 7 && SUP != "")
                    {
                        exAgent.WorkSheet.Rows[x].Font.Color = 900000;
                    }
                    if(I <=7 && I >0 && SUP != "" )
                    {
                        exAgent.WorkSheet.Rows[x].Font.Color = 999900;
                    }
                    x++;
                }

            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
        }
        
        public override void WriteExcelReport(string fileType)
        {
            string filename = "";
            string sheetName = "";
            string Standard = "MVTVKEK";
            strExcelFile = @"MVT\MVTStandard.xls";
            string filePath = @"C:\intex.w\Report\" + strExcelFile;
            exAgent.Open(filePath);
            //exAgent.Company = strCompany;
            exAgent.strExcelFile = strExcelFile;
            string filedate = DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString() + DateTime.Now.Day.ToString();
            filename = @"订单跟踪" + filedate + ".xls";
            sheetName = DateTime.Now.ToShortTimeString().Replace(@":", "");
            exAgent.CreateNewSheet(filename, Standard, sheetName);
            FillInExcelData(columns, dsSource, 3, 1);
            base.WriteExcelReport("OpenExcel");
        }
        #endregion
    }
}